package com.ruoyi.common.qy.utils;

public class SecondsConverter {

    /**
     * 秒数转换为 分:秒 格式 (例如：65秒 → 1:05)
     */
    public static String toMinutesAndSeconds(int totalSeconds) {
        if (totalSeconds < 0) {
            throw new IllegalArgumentException("秒数不能为负数");
        }

        int minutes = totalSeconds / 60;
        int seconds = totalSeconds % 60;

        return String.format("%d:%02d", minutes, seconds);
    }

    /**
     * 秒数转换为 时:分:秒 格式 (例如：3665秒 → 1:01:05)
     */
    public static String toHoursMinutesSeconds(int totalSeconds) {
        if (totalSeconds < 0) {
            throw new IllegalArgumentException("秒数不能为负数");
        }

        int hours = totalSeconds / 3600;
        int minutes = (totalSeconds % 3600) / 60;
        int seconds = totalSeconds % 60;

        return String.format("%d:%02d:%02d", hours, minutes, seconds);
    }

    /**
     * 秒数转换为中文格式 (例如：3665秒 → 1小时1分钟5秒)
     */
    public static String toChineseFormat(long totalSeconds) {
        if (totalSeconds < 0) {
            throw new IllegalArgumentException("秒数不能为负数");
        }

        long hours = totalSeconds / 3600;
        long minutes = (totalSeconds % 3600) / 60;
        long seconds = totalSeconds % 60;

        StringBuilder sb = new StringBuilder();

        if (hours > 0) {
            sb.append(hours).append("小时");
        }
        if (minutes > 0) {
            sb.append(minutes).append("分钟");
        }
        if (seconds > 0 || sb.length() == 0) {
            sb.append(seconds).append("秒");
        }

        return sb.toString();
    }
}
